package org.lex.dbq.view.template;

import org.lex.dbq.model.bo.Variable;

public class VariableMetaData {
	static final String[] PROPERTY_NAMES = { "0",// name
			"1",// display name
			"2", // default value
			"3", // required
			"4", // secret
			"5"// description
	};

	static final String[] PROPERTY_DISPLAY_NAMES = { "Name", "Display Name", "Default Value", "Required", "Secret", "Description" };

	public static Object getProperty(Variable var, int column) {
		Object value = null;
		switch (column) {
		case 0:
			value = var.getName();
			break;
		case 1:
			value = var.getDisplayName();
			break;
		case 2:
			value = var.getDefaultValue();
			break;
		case 3:
			value = var.isRequired();
			break;
		case 4:
			value = var.isSecret();
			break;
		case 5:
			value = var.getDescription();
			break;
		default:
			value = column + " invalid";
			break;
		}
		return value;
	}

	public static Object getProperty(Variable var, String propertyName) {
		return getProperty(var, Integer.parseInt(propertyName));
	}

	public static void setProperty(Variable var, String propertyName, Object newValue) {
		int index = Integer.parseInt(propertyName);
		String value = String.valueOf(newValue);
		switch (index) {
		case 0:
			var.setName(value);
			break;
		case 1:
			var.setDisplayName(value);
			break;
		case 2:
			var.setDefaultValue(value);
			break;
		case 3:
			var.setRequired(Boolean.parseBoolean(value));
			break;
		case 4:
			var.setSecret(Boolean.parseBoolean(value));
			break;
		case 5:
			var.setDescription(value);
			break;
		default:
			System.err.println(propertyName + " invalid");
			break;
		}
	}
}
